package com.peter.proxy.hkgolden.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Singleton;

@Singleton
@SuppressWarnings("serial")
public class ComposeMessage extends HttpServlet {

	protected final Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		logger.debug("doGet()");

		int messageId = 0;
		int replyId = 0;
		try {
			try {
				messageId = Integer.parseInt(req.getParameter("message"));
			} catch (Exception e) {
			}
			try {
				replyId = Integer.parseInt(req.getParameter("reply"));
			} catch (Exception e) {
			}

			// // Get message quote from HKGolden web service
			// // Define web service URL
			// URL url = new URL("http://forum2.hkgolden.com/"
			// + "MessageFunc.asmx/quote_message");
			// // Get connection from URL object
			// URLConnection urlConnection = url.openConnection();
			// // Set request property as request data will be in JSON format
			// urlConnection.setRequestProperty("Content-Type",
			// "application/json; charset=utf-8");
			// // Get OutputStreamWriter to write request data
			// urlConnection.setDoOutput(true);
			// OutputStreamWriter streamWriter = new OutputStreamWriter(
			// urlConnection.getOutputStream());
			// // Construct request data
			// String data = "{'s_MessageID':" + messageId + ",'s_ReplyID':"
			// + replyId + "}";
			// streamWriter.write(data);
			// streamWriter.flush();
			// // Send request to server
			// urlConnection.connect();
			// // Set timeout to read from server as 30 seconds
			// urlConnection.setReadTimeout(30000);
			// // Read response from server
			// BufferedReader buffReader = new BufferedReader(
			// new InputStreamReader(urlConnection.getInputStream(),
			// "Big5"));
			// // Parse response data and print message quote
			// JSONObject jsonObj = new JSONObject(buffReader.readLine());
			// jsonObj.getString("d");
			// buffReader.close();
			req.getRequestDispatcher("/composeMessage.jsp").forward(req, resp);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
